//
//  LabelAndCollectionReusableView.m
//  14_UICollectionViewTest
//
//  Created by 徐昊 on 16/8/2.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "LabelAndCollectionReusableView.h"
#define kCollectionViewReuse @"reuseSmall"
@interface LabelAndCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UILabel *label;
@end
@implementation LabelAndCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 50)];
        _label.text = @"分类";
        // collectionView
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, CGRectGetHeight(frame) - 50) collectionViewLayout:flow];
        CGFloat height = CGRectGetHeight(_collectionView.bounds) - 40;
        flow.itemSize = CGSizeMake((CGRectGetWidth(frame) - 30) / 2, height / 3);
//        flow.minimumLineSpacing = 0;
//        flow.minimumInteritemSpacing = 0;
//        flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 0);
        flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewReuse];
        [self addSubview:_label];
        [self addSubview:_collectionView];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}
@end
